<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@page import="iwpl.project.dao.EquipmentsDAO"%>
<%@page import="iwpl.project.entities.Equipments"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.net.CookieHandler"%>
<%@page import="iwpl.project.entities.EquipmentHistories"%>
<%@page import="iwpl.project.dao.EquipmentHistoriesDAO"%>
<%@page import="java.sql.ResultSet"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
//List<Equipments> list=(List<Equipments>)request.getParameterValues("list");

//String text=(document.form1.txtName.value()!=null?document.form1.txtName.value(): null);
List<Equipments> list1 =(List<Equipments>)session.getAttribute("phuoc");
//String t = (String)session.getAttribute("Manage_EquipmentHistories");
//if(t!="active")
	//{response.sendRedirect("index.jsp");}
%>
<link rel="stylesheet" href="css/CommonCSS.css" type="text/css" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>

		<title>Manage Equipment</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">

		<link rel="stylesheet" href="css/datepicker.css" type="text/css" />
		<link rel="stylesheet" href="css/commonCSS.css" type="text/css" />
		<script type="text/javascript" src="js/datepicker.js"></script>
		<script src="js/jquery-Source.js"></script>
		<script type="text/javascript" src="js/jquery-Validation.js"></script>
		<script type="text/javascript">
  $(document).ready(function()
  {
    $("#commentForm").validate();
  });
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

	
	
  </script>
	</head>
	<body>
		<table>
			<tr>
				<td>
					<form name="form1" action="./servlet/Control_Equipment"
						method="post">
						<table>
							<tr>
								<h3>
									Equipments Histories
									<br>
								</h3>
							</tr>
							<tr>
								<td> 
									Search For Employee Name 
 
								</td>
								<td>
									<input type="text" name="txtSearch" style="width: 160px;"
										class="required">
									<input type="hidden" name="action" value="search"
										style="width: 200px;">
								</td>
							</tr>
							<tr>
								<td> 
									Search For Maintain Date&nbsp; 
								</td>
								<td>
									From
									<img src="./images/file_temporary.png"
										onclick="displayDatePicker('txtFrom', this);" width="26"
										height="21" />
									<input type="text" name="txtFrom" style="width: 100px;"
										id="cdate" readonly="readonly" class="required">
									To
									<img src="./images/file_temporary.png"
										onclick="displayDatePicker('txtTo', this);" width="26"
										height="21" />
									<input type="text" name="txtTo" style="width: 100px;"
										id="cdate" readonly="readonly" class="required">
								</td>
							</tr>

						</table>

						<table>
							<tr>

								<td>
									<button name="btnInsert" type="button"
										style="width: 70px; height: 25px; margin-right: 5px; text-align: center"
										value="Insert" onclick="doInsert()";>
										Insert
									</button>
								</td>
								<td>
									<button name="btnReset" type="reset"
										style="width: 70px; height: 25px; margin-right: 5px; text-align: center"
										value="Reset">
										Reset
									</button>
								</td>
								<td>
									<button name="btnSearch" type="submit"
										style="width: 70px; height: 25px; margin-right: 5px; text-align: center"
										value="Search" class="submit">
										Search
									</button>
								</td>

							</tr>
						</table>
					</form>

					<%	

						EquipmentHistoriesDAO dao = new EquipmentHistoriesDAO();
							//List<EquipmentHistories> list=list1;
							//List<EquipmentHistories> list=dao.findAll();
								List<EquipmentHistories> list=dao.findAll2();
							if(list!=null)
							{
								//list = list1;
								int i = 0;
							out.println("<table border=1 width=770>");
							out.println("<tr bgcolor=5f9ff5>");
							out.println("<td width=20>No</td>");
							out.println("<td>Emp Name</td>");
							out.println("<td>Apart No</td>");
							out.println("<td>Equip Name</td>");
							out.println("<td>Maintain</td>");
							out.println("<td>Description</td>");
							out.println("<td></td>");
							out.println("<td></td></tr>");
							out.println("</tr>");
							EquipmentHistories equip;
								for (Iterator<EquipmentHistories> it = list.iterator(); it.hasNext();) 
								{
									equip = (EquipmentHistories) it.next();
									i++;

									if (i % 2 != 0) 
									{
										out.println("<tr bgcolor=\"#CCFFFF\">");
									} 
									else 
									{
										out.println("<tr bgcolor=\"#99CCCC\">");
									}
											out.println("<td>" + i + "</td>");
											out.println("<td>" + equip.getEmployees().getId()+" - "+ equip.getEmployees().getFullName() + "</td>");
											out.println("<td>" +equip.getEquipmentDetails().getApartments().getApartmentNumber()+"</td>");
											out.println("<td>" + equip.getEquipmentDetails().getEquipments().getEquipmentName() + "</td>");
											String date1=equip.getMaintainDate().getMonth()+1 +"-"+equip.getMaintainDate().getDate()+"-"+equip.getMaintainDate().toString().substring(0,4);
											out.println("<td>" + date1 +"</td>");
											out.println("<td>" + equip.getDescriptions() + "</td>");
							
											out.println("<td align=center><a href=" + "/DepartmentManage/Update_EquipmentHistories.jsp?id="
													+ equip.getId() + " /><img src="
													+ "./images/Edit.jpg" + " /></td>");
										
											out.println("<td align=center><a href=javascript:doDelete('"
												+ equip.getId() + "') /><img src="
												+ "./images/Delete.jpg" + " /></td></tr>");
								}
								out.println("</table>");
							//list1.clear();
							//list.clear();	
								
							}
							
							else
							{
								//out.println("Press Search Button To Get Data");
							}					
								%>

				</td>
			</tr>
		</table>

		<script type="text/javascript">
function doInsert(){
		location.href="Insert_EquipmentHistories.jsp";
}
function doDelete(id){
		var x=window.confirm("Do you want to delete this Equipment?");
				if(x)
				location.href = "./servlet/Control_EquipmentHistories?id=" + id+"&action=delete";
}
function doUpdate(id){
		
				
				location.href = "Update_EquipmentHistories?id=" + id;
}
</script>
	</body>
</html>
